package com.julang.check.translate.jinshan;

import com.alibaba.fastjson.JSONObject;
import com.julang.check.translate.common.AbstractOnlineTranslator;
import com.julang.check.translate.common.HttpParams;
import com.julang.check.translate.common.HttpPostParams;
import com.julang.check.translate.common.LANG;
/**
 * @author 赵自强
 * */
public class JinshanTranslator extends AbstractOnlineTranslator {

    public JinshanTranslator(){
        langMap.put(LANG.EN, "en");
        langMap.put(LANG.ZH, "zh");
    }

    @Override
    protected String getResponse(LANG from, LANG targ, String query) throws Exception{
        HttpParams params = new HttpPostParams()
                .put("f", langMap.get(from))
                .put("t", langMap.get(targ))
                .put("w", query);

        return params.send2String("http://fy.iciba.com/ajax.php?a=fy");
    }


    @Override
    protected String parseString(String jsonString){
        JSONObject jsonObject = JSONObject.parseObject(jsonString);
        String result = jsonObject.getJSONObject("content").getString("out");
        return result;
    }
}
